/*
 * @Description: 工具类
 * tips：格式化时，末尾有逗号就会自动换行，没有就是自动排布到一行
 *
 * @Date: 2022-06-10 15:11:03
 * @LastEditTime: 2022-06-22 11:25:24
 */

export const authAdapter = (key: any) => {
  let authTemp: any = 0;
  if (key === '个人视角') {
    authTemp = 0;
  }
  if (key === '子方向视角') {
    authTemp = 1;
  }
  if (key === '方向视角') {
    authTemp = 2;
  }
  if (key === '管理员视角') {
    authTemp = 3;
  }
  return authTemp;
};

export const authAdapter2 = (key: any) => {
  let authTemp: any = '';
  if (key === '个人视角') {
    authTemp = 'personal';
  }
  if (key === '子方向视角') {
    authTemp = 'group';
  }
  if (key === '方向视角') {
    authTemp = 'direction';
  }
  if (key === '管理员视角') {
    authTemp = 'all';
  }
  return authTemp;
};

/**
 * 处理Descriptions中的审核通过状态
 * @param is_pass_num 审核通过状态值
 * @returns
 */
export const isPassAdapter = (is_pass_num: string) => {
  switch (is_pass_num + '') {
    case '-1':
      return '待管理员审核';
    case '0':
      return '待上传文件';
    case '1':
      return '审核中';
    case '2':
      return '待方向负责人审核';
    case '3':
      return '';
    case '4':
      return '审核通过';
  }
};

/**
 * 处理Descriptions中的标签
 * @param label_data 标签数据列表 [{label、value},{}]
 * @param label_nums 表单回填标签值列表 [1、2、3]
 * @returns
 */
export const getLabelAdapter = (label_data: [], label_nums: []) => {
  let labels = '';
  (label_nums || [])?.map((e) => {
    (label_data || []).forEach((label) => {
      if (label?.value == e) labels += label?.label + '；';
    });
  });
  return labels;
};

/**
 * 模板下载链接
 * @param tableName 模块对应的数据库表名称
 * @returns 模板下载地址
 */
export const TemplateUrlAdapter = (tableName: String) => {
  switch (tableName) {
    case 'PAPER':
      return 'http://10.1.40.84:9998/nfile/%E8%AE%BA%E6%96%87%E4%B8%8A%E4%BC%A0%E6%A8%A1%E6%9D%BF.xlsx';
    case 'BOOK_PUBLISH':
      return 'http://10.1.40.84:9998/nfile/%E4%B8%93%E8%91%97%E4%B8%8A%E4%BC%A0%E6%A8%A1%E6%9D%BF.xlsx';
    case 'STANDARD':
      return 'http://10.1.40.84:9998/nfile/%E6%A0%87%E5%87%86.xlsx';
    case 'HORIZONTAL_PROJECT':
      return 'http://10.1.40.84:9998/nfile/%E6%A8%AA%E5%90%91%E9%A1%B9%E7%9B%AE.xlsx';
    case 'VERTICAL_PROJECT':
      return 'http://10.1.40.84:9998/nfile/%E7%BA%B5%E5%90%91%E9%A1%B9%E7%9B%AE.xlsx';
    case 'GRANT_PATENT':
      return 'http://10.1.40.84:9998/nfile/%E7%94%B3%E8%AF%B7%E3%80%81%E6%8E%88%E6%9D%83%E4%B8%93%E5%88%A9.xlsx';
    case 'ACHIEVE_TRANS':
      return 'http://10.1.40.84:9998/nfile/%E6%88%90%E6%9E%9C%E8%BD%AC%E5%8C%96%E6%A8%A1%E6%9D%BF.xlsx';
    case 'SOFTWARE_COPYRIGHT':
      return 'http://10.1.40.84:9998/nfile/%E8%BD%AF%E4%BB%B6%E8%91%97%E4%BD%9C%E6%9D%83%E6%A8%A1%E6%9D%BF.xlsx';
    case 'EQUIPMENT_DEVELOP':
      return 'http://10.1.40.84:9998/nfile/%E4%BB%AA%E5%99%A8%E8%AE%BE%E5%A4%87%E4%B8%8A%E4%BC%A0%E6%A8%A1%E6%9D%BF.xlsx';
    case 'INTER_CPT_PROJECT':
      return 'http://10.1.40.84:9998/nfile/%E5%9B%BD%E9%99%85%E5%90%88%E4%BD%9C%E9%A1%B9%E7%9B%AE.xlsx';
    case 'YEAR_AND_OTHER_ACHIEVE':
      return 'http://10.1.40.84:9998/nfile/%E5%85%B6%E4%BB%96%E3%80%81%E5%B9%B4%E5%BA%A6%E6%88%90%E6%9E%9C%E4%B8%8A%E4%BC%A0%E6%A8%A1%E6%9D%BF.xlsx';
    case 'REWARD':
      return 'http://10.1.40.84:9998/nfile/%E5%A5%96%E5%8A%B1%E4%B8%8A%E4%BC%A0%E6%A8%A1%E6%9D%BF.xlsx';
    case 'LAB_STAFF_REPORT': //实验室特邀报告
      return 'http://10.1.40.84:9998/nfile/%E5%AE%9E%E9%AA%8C%E5%AE%A4%E7%89%B9%E9%82%80%E6%8A%A5%E5%91%8A%281%29.xlsx';
    case 'INVITATION_REPORT': //大会报告、大会特邀报告
      return 'http://10.1.40.84:9998/nfile/%E5%A4%A7%E4%BC%9A%E6%8A%A5%E5%91%8A%E5%92%8C%E5%A4%A7%E4%BC%9A%E7%89%B9%E9%82%80%E6%8A%A5%E5%91%8A%281%29.xlsx';
    case 'VISIT_ENTERPRISE': //国内外学术交流
      return 'http://10.1.40.84:9998/nfile/%E5%9B%BD%E5%86%85%E5%A4%96%E5%AD%A6%E6%9C%AF%E4%BA%A4%E6%B5%81%E6%A8%A1%E6%9D%BF.xlsx';
    default:
      return '';
  }
};
/**
 * 页面标头
 * @param pageType 新建或id
 * @param item localStorage.getItem('isEdit')
 * @param theme 模块标识
 * @returns
 */
export const TitleAdapter = (pageType: any, item: any, theme: any) => {
  if (pageType == 'new') {
    return '新建' + theme;
  } else if (item === '查看') {
    return '查看' + theme + '详情';
  } else {
    return '编辑' + theme;
  }
};

/**
 * 延时函数
 * @param time 毫秒数
 * @returns 等待对应毫秒数
 */
const waitTime = (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};
